<template>
  <a-modal
    title="运费修改"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
    style="top:20px;"
  >
    <a-spin :spinning="confirmLoading">

      <a-form :form="form">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="订单编号">
          {{ this.model.id }}
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="当前运费金额">
          {{ this.model.freightAmount }}
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="修改运费金额">
          <a-input placeholder="请输入运费" v-decorator="['freightAmount', {}]"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import { httpAction } from '@/api/manage'
  import { getAction } from '@/api/manage'

  export default {
    name: "OmsOrderEditFreightModal",
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        form:this.$form.createForm(this),
        url: {
          edit: "/oms/omsOrder/editFreight",
        },
      }
    },
    created () {
      console.log("created");
    },
    methods: {
      show(record) {
        //this.form.resetFields();
        this.visible = true;
        this.model = record;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'freightAmount'))
        });
      },
      close () {
        this.form.resetFields();
        this.$emit('close');
        this.visible = false;
      },
      handleSubmit () {
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            console.log(values)
            this.confirmLoading = true;
            let formData = {};
            formData.id = this.model.id;
            formData.freightAmount = values.freightAmount
            console.log(formData)
            httpAction(this.url.edit,formData,'put').then((res)=>{
              if(res.success){
                this.$message.success(res.message);
                this.$emit('ok');
              }else{
                this.$message.warning(res.message);
              }
            }).finally(() => {
              this.confirmLoading = false;
              this.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>